<?php


    class CUserLogs {

        public static function get_client_ip() {
            return $_SERVER['REMOTE_ADDR'];
        }


        public static function Add($message,$level,$user="") {

            if($user=="") {
                $user = Yii::app()->user->id;
            }

            $command = Yii::app()->db->createCommand();
            $command->insert('logs', array(
                'timestamp'=>new CDbExpression('NOW()'),
                'user'=>$user,
                'ip'=>self::get_client_ip(),
                'level'=>$level,
                'message'=>$message
            ));

        }

        public static function INFO($message,$user="") {
            self::Add($message,0,$user);
        }

        public static function MINOR($message, $user="") {
            self::Add($message,1,$user);
        }

        public static function MAJOR($message,$user="") {
            self::Add($message,2,$user);
        }

        public static function CRITICAL($message,$user="") {
            self::Add($message,3,$user);
        }


    }



?>